package com.authine.cloudpivot.web.api.controller;

import com.authine.cloudpivot.engine.api.model.organization.UserModel;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.dubbo.DubboConfigService;
import com.authine.cloudpivot.web.api.service.CheckUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Api(description = "和记黄埔相关接口", tags = "校验用户")
@RestController
@RequestMapping("/api/check")
@Slf4j
@Validated
@Component
public class CheckUserController extends BaseController {

    @Autowired
    private CheckUserService checkUserService;
    @Autowired
    private DubboConfigService dubboConfigService;

    /**
     * @Description : 根据微信查询的信息，返回查询后的对象到前端页面
     * @param ： sourceId
     * @author : Liun
     * @date : 2020/8/12
     */
    @ApiOperation(value = "校验用户" )
    @PostMapping("/checkUser")
    @ResponseBody
    public UserModel checkUser(String sourceId){
      UserModel userModel=new UserModel();
        String objectId= checkUserService.checkUser(sourceId);
       if(ObjectUtils.allNotNull(objectId)){
           userModel=dubboConfigService.getOrganizationFacade().getUser(String.valueOf(objectId));
       }
       return userModel;
    }

}
